package com.vision.web;

import com.vision.common.aes.AES;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.IOException;

/**
 * @Filename ParamsFilterHandler.java
 * @Description
 * @Version 1.0
 * @Author zhongc
 * @Email zhong_ch@foxmail.com
 * @History <li>Author: zhongc</li>
 * <li>Date: 2017/5/24</li>
 * <li>Version: 1.0</li>
 * <li>Content: create</li>
 */
public class ParamsFilterHandler implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        /*FilteredRequest requestWrapper = new FilteredRequest(servletRequest);
        requestWrapper.getParameter("params");
        filterChain.doFilter(new FilteredRequest(servletRequest), servletResponse);*/
    }

    static class FilteredRequest extends HttpServletRequestWrapper {

        public FilteredRequest(ServletRequest request) {
            super((HttpServletRequest) request);
        }

        public String getParameter(String paramName) {
            String value = super.getParameter(paramName);
            try {
                return AES.decode(value);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

    }

    @Override
    public void destroy() {

    }
}
